package com.wxzz.elearing.pay.api.admin;


import com.alibaba.fastjson.JSONObject;
import com.wxzz.elearing.pay.dto.UserIdGetUserWalletDto;
import com.wxzz.elearing.pay.entity.UserOrder;
import com.wxzz.elearing.pay.entity.UserWallet;
import com.wxzz.elearing.pay.service.IUserOrderService;
import com.wxzz.elearing.pay.service.IUserWalletService;
import com.wxzz.elearning.common.vo.JgPageVo;
import com.wxzz.elearning.common.vo.ReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 用户钱包 前端控制器
 * </p>
 *
 * @author
 * @since 2021-04-23
 */
@RestController
@RequestMapping("/user-wallet")
@Api(tags = "钱包接口(后台)")
public class UserWalletController {

    @Autowired
    private IUserWalletService userWalletService;

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @ApiOperation(value = "查看当前用户钱包(后台)", notes = "查看当前用户钱包(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "tokenGetUserWallet/{userType}", method = RequestMethod.POST)
    public ReturnVO<UserWallet> tokenGetUserWallet(@RequestHeader String token, @ApiParam("0-平台端 1-企业端 2-用户端 3-讲师端") @PathVariable Integer userType) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return userWalletService.tokenGetUserWallet(jsonObject, userType);
    }

    @ApiOperation(value = "根据用户id换取用户钱包(后台)", notes = "根据用户id换取用户钱包(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "userIdGetUserWallet", method = RequestMethod.POST)
    public ReturnVO<UserWallet> userIdGetUserWallet(@Valid @RequestBody UserIdGetUserWalletDto userIdGetUserWalletDto) {
        return userWalletService.userIdGetUserWallet(userIdGetUserWalletDto);
    }

}
